/**
 * webpack 联邦模块配置
 */
import { getEvnData } from './environments';
const { ModuleFederationPlugin } = require('webpack').container;
var umiEnv = process.env.UMI_ENV;

// 环境
var environment = process.env.PROJECT_ENV || 'localhost';
var envData = getEvnData(environment)

// 加载oss的代码资源
var ossPublicResource = envData['process.env.ossPublicResource'];

// 项目名称
var ossUrl = envData['process.env.ossUrl']
var proejctName = 'web-microApp-module-moduleFederation'

// 设置MF
export default function initMF(config) {
  var mf1 = 'mf1@//localhost:31790/remoteEntry.js';
  if (umiEnv == 'production' || ossPublicResource) {
    mf1 = `mf1@${ossUrl}/${proejctName}/dist/remoteEntry.js`;
  }

  // 打包
  config.plugin('mf').use(ModuleFederationPlugin, [
    {
      name: 'mfBasic',
      filename: 'remoteEntry.js',
      remotes: {
        mf1: mf1,
      },
      // shared: ['react'],
    },
  ]);
}
